package com.han.cloud.controller;

import com.han.cloud.dto.TradeDTO;
import com.han.cloud.dto.WrapperResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @author hanky
 * @date 2021/10/17
 */
@RestController
public class OrderController {

    private static final String PAYMENT_URL = "http://HAN-PAYMENT-CLOUD";

    @Resource
    private RestTemplate restTemplate;

    @PostMapping("/create")
    public WrapperResponse<String> create(@RequestBody TradeDTO tradeDTO) {
        return restTemplate.postForObject(PAYMENT_URL + "/saveTrade", tradeDTO, WrapperResponse.class);
    }

    @GetMapping("/get")
    public WrapperResponse<TradeDTO> get(String id) {
        return restTemplate.getForObject(PAYMENT_URL + "/getTrade?id=" + id, WrapperResponse.class);
    }
}
